import 'package:daily/page1.dart';
import 'package:daily/page2.dart';
import 'package:daily/page3.dart';
import 'package:daily/splash.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Splash(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0; // 用于跟踪选中的按钮索引

  // 定义按钮标签
  List<String> _buttonLabels = [
    'daily1',
    'daily2',
    'daily3',
  ];

  // 定义对应每个按钮的内容
  List<Widget> _pageContents = [
    Page1(),
    Page2(),
    Page3(),
  ];

  // 处理按钮点击事件
  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Daily'),
      ),
      drawer: Drawer(
        child: ListView.builder(
          itemCount: _buttonLabels.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text(_buttonLabels[index]),
              selected: index == _selectedIndex, // 根据选中状态设置样式
              onTap: () {
                _onItemTapped(index); // 处理按钮点击事件
                Navigator.pop(context); // 关闭侧边栏
              },
            );
          },
        ),
      ),
      body: IndexedStack(
        index: _selectedIndex,
        children: _pageContents,
      ),
    );
  }
}
